#include "progressBar.h"
#define BLACK         "\033[0;30m"
#define RED           "\033[0;31m"
#define GREEN         "\033[0;32m"
#define YELLOW        "\033[0;33m"
#define BLUE          "\033[0;34m"
#define MAGENTA       "\033[0;35m"
#define CYAN          "\033[0;36m"
#define WHITE         "\033[0;37m"

#define RESET         "\033[0m"


const char* lable = "|/-\\";
char bar[NUM];

void process_bar(int rate)
{
  if(rate < 0 || rate > 100) return;
  char* array[] = {BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE};
  int len = strlen(lable);
  int len_a = sizeof(array) / sizeof(array[1]);
  printf("%s[%-100s][%d][%c]\r", array[rate % len_a], bar, rate, lable[rate % len]);
  //printf(RED"[%-100s]"RESET"[%d][%c]\r", bar, rate, lable[rate % len]);
  fflush(stdout);
  bar[rate++] = BODY;
  if(rate < 100)bar[rate] = RIGHT;

}

void initbar()
{
  memset(bar, '\0', sizeof(bar));
  printf(RESET);
}






















/*
void process_bar(int speed)
{
  char bar[NUM];
  memset(bar, 0, sizeof(bar));
  int len = strlen(lable);
  int cut = 0;
  while(cut <= TOP){
	printf("[%-100s][%d%%][%c]\r", bar, cut, lable[cut % len]);
	fflush(stdout);
	bar[cut++] = BODY;
	if(cut < TOP) 
	bar[cut] = RIGHT;
	usleep(speed);
  }
  printf("\n");
}
*/



